<template>
  <div>
    <tableComponents :pagination="{
        currentPage,
        pageSize: pagesize,
        total: turn_list.all_num
      }" @handleCurrentChange="handleCurrentChange" @handleSizeChange="handleSizeChange" :isShow="false" :isHaveExport="false"
        @toAdd="$router.push({ path: '/index/plugin/turntable_set' })" addText="新建幸运大转盘">
      <template v-slot:table>
        <el-table ref="multipleTable" :data="turn_list.data" v-loading="loading" stripe header-row-class-name="head_color" tooltip-effect="dark"
            style="width: 99.8%" @selection-change="handleSelectionChange">
          <el-table-column type="selection"></el-table-column>

          <el-table-column label="活动名称" min-width="150">
            <template slot-scope="scope">{{ scope.row.title }}</template>
          </el-table-column>
          <el-table-column label="开始时间" min-width="150">
            <template slot-scope="scope">{{
              scope.row.begin_time | getTimeFormat
            }}</template>
          </el-table-column>
          <el-table-column label="结束时间" min-width="150">
            <template slot-scope="scope">{{
              scope.row.end_time | getTimeFormat
            }}</template>
          </el-table-column>
          <el-table-column label="活动场景" min-width="150">
            <template slot-scope="scope">{{ scope.row.con }}</template>
          </el-table-column>
          <el-table-column label="参与次数" min-width="150">
            <template slot-scope="scope">{{ scope.row.join_limit }}</template>
          </el-table-column>
          <el-table-column label="参与人数" min-width="150">
            <template slot-scope="scope">{{
              scope.row.join_num || "0"
            }}</template>
          </el-table-column>
          <el-table-column label="领奖人数" min-width="150">
            <template slot-scope="scope">{{
              scope.row.win_num || "0"
            }}</template>
          </el-table-column>
          <el-table-column label="操作" min-width="150">
            <template slot-scope="scope">
              <el-button :loading="$store.state.isLoading" size="mini" type="primary" @click="edit_list_detail(scope.row.id)">编辑</el-button>
              <el-button :loading="$store.state.isLoading" size="mini" type="danger" @click="del_list_detail(scope.row.id)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
      <template v-slot:footerLeft>
        <a class="aBtn aBtn_1 aBtn_lan2" @click="deleteAll_turns">删除</a>
      </template>
    </tableComponents>
  </div>
</template>
<script>
import HeadTitle from "@/components/currency/HeadTitle.vue";

export default {
  name: "coin_must",
  data () {
    return {
      multipleSelection: [],
      loading: false,
      turn_list: {},
      currentPage: 1, //初始页
      pagesize: 10 //    每页的数据
    };
  },
  components: {
    HeadTitle
  },
  created () {
    this.get_turn_list(1);
  },
  methods: {
    deleteAll_turns (del_id) {
      //批量删除
      var str = "";
      if (this.multipleSelection.length <= 0) {
        this.$message.error("未选择批量删除");
      } else {
        for (var i in this.multipleSelection) {
          str += this.multipleSelection[i].id + "@";
        }
        str = str.slice(0, -1);
        this.$swal({
          title: "您确定要删除这些信息吗",
          text: "删除后将无法恢复，请谨慎操作！",
          type: "warning",
          showCancelButton: true,
          confirmButtonColor: "#DD6B55",
          confirmButtonText: "是的，我要删除",
          cancelButtonText: "容我三思"
        }).then(willDelete => {
          if (willDelete.value) {
            this.$api.getPlugin.del_turntable({ id_str: str }).then(res => {
              if (res.data.code == 200) {
                this.$swal("删除成功！", "您已经删除了这条信息。", "success");
                this.get_turn_list();
              } else {
                this.$swal("删除失败！", "出错啦！", "success");
                this.get_turn_list();
              }
            });
          }
        });
      }
    },
    del_list_detail (id) {
      //删除
      this.$swal({
        title: "您确定要删除这些信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思"
      }).then(willDelete => {
        if (willDelete.value) {
          this.$api.getPlugin.del_turntable({ id_str: id }).then(res => {
            if (res.data.code == 200) {
              this.$swal("删除成功！", "您已经删除了这条信息。", "success");
              this.get_turn_list();
            } else {
              this.$swal("删除失败！", "出错啦！", "success");
              this.get_turn_list();
            }
          });
        }
      });
    },
    handleSelectionChange (val) {
      this.multipleSelection = val;
    },
    edit_list_detail (id) {
      this.$store.commit("addbreadcrumbs", {
        title: "大转盘编辑",
        url: `/index/plugin/turntable_set?id=${id}`
      });
      this.$router.push({
        path: "/index/plugin/turntable_set",
        query: { id: id }
      });
    },

    // 初始页currentPage、初始每页数据数pagesize和数据data
    handleSizeChange: function (size) {
      //每页下拉显示数据

      this.pagesize = size;
      this.get_turn_list(1);
    },
    handleCurrentChange: function (currentPage) {
      //点击第几页
      this.currentPage = parseInt(currentPage);
      this.get_turn_list(this.currentPage);
    },

    get_turn_list (page) {
      this.loading = true;
      this.$api.getPlugin
        .get_turntable({ page: page, page_size: this.pagesize })
        .then(res => {
          if (res.data.code == 200) {
            this.turn_list = res.data.result;
            this.loading = false;
          } else {
            this.loading = false;
          }
        });
    }
  }
};
</script>
<style scoped></style>
